<load href="__PUBLIC__/datepicker/css/datetimepicker.css" />
<load href="__PUBLIC__/datepicker/js/datetimepicker.js" />
<div id="data_page" class="in_page">
    <div class="panel panel-default">
        <div class="panel-body" style="position: relative">
            <form class="form-inline" onsubmit="return checkSearch()">
                <div class="form-group">
                    <label for="exampleInputName2">用户名</label>
                    <input id="keyword" value="{$search.keyword}" type="text" name="keyword" class="form-control"  placeholder="输入用户名或订单号" />
                    <input value="1" type="hidden" name="p" class="form-control" />
                </div>
                <div class="form-group">
                    <label >支付类型</label>
                    <select style="width: 100px;" name="payment_type" id="payment_type" class="form-control">
                        <if condition="$search.payment_type eq '0'">
                            <option value=""  >全部</option>
                            <option value="0" selected  >支付宝</option>
                            <option value="1">微信</option>
                        </if>
                        <if condition="$search.payment_type eq '1'">
                            <option value=""  >全部</option>
                            <option value="0"  >支付宝</option>
                            <option value="1" selected  >微信</option>
                        </if>
                        <if condition="$search.payment_type eq ''">
                            <option selected value=""  >全部</option>
                            <option value="0"  >支付宝</option>
                            <option value="1"   >微信</option>
                        </if>
                    </select>
                </div>
                <div class="form-group">
                    <label >支付状态</label>
                    <select style="width: 100px;" name="payment_status" id="payment_status" class="form-control">
                        <if condition="$search.payment_status eq '0'">
                            <option value=""  >全部</option>
                            <option value="0" selected  >未支付</option>
                            <option value="1">已支付</option>
                            <option value="2">支付失败</option>
                        </if>
                        <if condition="$search.payment_status eq '1'">
                            <option value=""  >全部</option>
                            <option value="0"   >未支付</option>
                            <option value="1" selected>已支付</option>
                            <option value="2">支付失败</option>
                        </if>
                        <if condition="$search.payment_status eq '2'">
                            <option value="">全部</option>
                            <option value="0">未支付</option>
                            <option value="1">已支付</option>
                            <option value="2" selected>支付失败</option>
                        </if>
                        <if condition="$search.payment_status eq ''">
                            <option value="" selected>全部</option>
                            <option value="0">未支付</option>
                            <option value="1">已支付</option>
                            <option value="2" >支付失败</option>
                        </if>
                    </select>
                </div>
                <div class="form-group">
                    <label >支付状态</label>
                    <select style="width: 100px;" name="order_status" id="order_status" class="form-control">
                        <if condition="$search.order_status eq '0'">
                            <option value=""  >全部</option>
                            <option value="0" selected  >待支付</option>
                            <option value="1">已支付</option>
                            <option value="2">订单超时</option>
                            <option value="3">订单取消</option>
                        </if>
                        <if condition="$search.order_status eq '1'">
                            <option value=""  >全部</option>
                            <option value="0"   >待支付</option>
                            <option value="1" selected>已支付</option>
                            <option value="2">订单超时</option>
                            <option value="3">订单取消</option>
                        </if>
                        <if condition="$search.order_status eq '2'">
                            <option value=""  >全部</option>
                            <option value="0"   >待支付</option>
                            <option value="1" >已支付</option>
                            <option value="2" selected>订单超时</option>
                            <option value="3">订单取消</option>
                        </if>
                        <if condition="$search.order_status eq '3'">
                            <option value=""  >全部</option>
                            <option value="0"   >待支付</option>
                            <option value="1" >已支付</option>
                            <option value="2" >订单超时</option>
                            <option value="3" selected>订单取消</option>
                        </if>
                        <if condition="$search.order_status eq ''">
                            <option value="" selected  >全部</option>
                            <option value="0"   >待支付</option>
                            <option value="1" >已支付</option>
                            <option value="2" >订单超时</option>
                            <option value="3">订单取消</option>
                        </if>
                    </select>
                </div>
                <div class="form-group">
                    <label >下单时间</label>
                    <input id="begin_time" value="{$search.begin_time}" type="text" name="begin_time" class="form-control"  placeholder="输入开始时间" />
                    <input id="end_time" value="{$search.end_time}" type="text" name="end_time" class="form-control"  placeholder="输入结束时间" />
                </div>
                <button type="submit" class="btn btn-sm btn-default">搜索</button>
                <div class="btn-group">
                    <button type="button" onclick="resetData()" class="btn btn-sm btn-primary">重置</button>
                </div>
            </form>
        </div>
    </div>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>#ID</th>
            <th>用户</th>
            <th>订单号</th>
            <th>单价</th>
            <th>购买数</th>
            <th>总价格</th>
            <th>总余额</th>
            <th>支付状态</th>
            <th>订单状态</th>
            <th>下单时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <volist name="list" id="item">
        <tr>
            <th scope="row">{$item.id}</th>
            <td>{$item.username}</td>
            <td>{$item.order_sn}</td>
            <td>{$item.price}</td>
            <td>{$item.number}</td>
            <td>{$item.total_price}</td>
            <td>{$item.total_balance}</td>
            <td>
                <if condition="$item.payment_status eq '0'">
                    未支付
                </if>
                <if condition="$item.payment_status eq '1'">
                    已支付
                </if>
                <if condition="$item.payment_status eq '2'">
                    支付失败
                </if>
                <if condition="$item.payment_type eq '1'">
                    （微信支付）
                </if>
                <if condition="$item.payment_type eq '0'">
                    （支付宝）
                </if>
            </td>
            <td>
                <if condition="$item.order_status eq '0'">
                    待支付
                </if>
                <if condition="$item.order_status eq '1'">
                    已支付
                </if>
                <if condition="$item.order_status eq '2'">
                    订单超时
                </if>
                <if condition="$item.order_status eq '3'">
                    订单取消
                </if>
            </td>
            <td  style="text-align: center;width: 140px;">{$item.createdtime|date="Y-m-d H:i",###}</td>
            <td style="text-align: center"><button type="button" onclick="handleItem('{:U('/balance/updateOrder')}',{$item.id})" class="btn btn-primary btn-xs">查看/修改</button></td>
        </tr>
        </volist>
    </table>
    {$page}
</div>

<script>
    $(function(){
        $('#begin_time').datetimepicker({
            lang: 'ch',
            format: 'Y-m-d H:i',
            timepicker: true,
            step:10
        });
        $('#end_time').datetimepicker({
            lang: 'ch',
            format: 'Y-m-d H:i',
            timepicker: true,
            step:10
        });
    })
    function checkSearch(){
        _sdate = $("#begin_time").val();
        _etime = $("#end_time").val();
        if (_sdate != '' && _etime == '') {
            alert('请输入时间条件的结束时间');
            return false;
        }
        if (_sdate == '' && _etime != '') {
            alert('请输入时间条件的开始时间');
            return false;
        }
        if (Date.parse(_sdate) - Date.parse(_etime) > 0) {
            alert('时间条件的开始时间不得大于结束时间');
            return false;
        }
        return true;
    }

    function resetData(){
        $("#username").val("");
        $("#to_username").val("");
        $("#begin_time").val("");
        $("#end_time").val("");
    }

    function handleItem(_action,id,_title){
        showIframe(_action+"?id="+id,"查看修改订单",'80%','96%');
    }


</script>